<?php
namespace App\Http\Controllers\ApiApp;

use App\DBs\OrderDB;
use Illuminate\Http\Request;

class OrderController extends BaseController
{
    //用户

    protected $db;

    public function __construct()
    {
        parent::__construct();
        $this->db = new OrderDB();
    }

    /**
     * 列表
     */
    public function getIndex(Request $request)
    {
        $resDb = $this->db->getIndex();
        if ($resDb['code']!=0) {
            return $this->toAppJson(-3);
        }
        $items = $resDb['data'];
        return $this->toAppJson(0,$items);
    }

    /**
     * 新增
     */
    public function setAdd(Request $request)
    {
        $uname = $request->post('uname','');
        $title = $request->post('title','');
        $num = $request->post('num',0);
        $money = $request->post('money',0);
        if (!$uname || !$title) {
            return $this->toAppJson(-2);
        }
        $resDb = $this->db->setAdd($uname,$title,$num,$money);
        if (!$resDb) {
            return $this->toAppJson(-500);
        }
        return $this->toAppJson(0);
    }
}